<?php

namespace App\Transformers\Frontend;

use App\Models\Order\Order;
use League\Fractal\TransformerAbstract;

class OrderTransformer extends TransformerAbstract
{

    protected $availableIncludes = [
        'item'
    ];

    public function transform(Order $model)
    {
        return $model->attributesToArray();
    }

    public function includeItem(Order $model)
    {
        $item = $model->item;
        if (!$item){
            return $this->null();
        }
        return $this->item($item, new OrderItemTransformer());
    }
}